<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta content="text/html;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta http-equiv ="Pragma" content = "no-cache"/>
	<meta http-equiv="Cache-Control" content="no cache" />
	<meta http-equiv="Expires" content="0" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="format-detection" content="telephone=no"/>
	<script src="/static/fsLayui/scripts/pace.min.js"></script>
	<link href="/static/fsLayui/css/pace-theme-flash.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/fsLayui/plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" type="text/css" href="/static/fsLayui/css/fs.css" media="all"/>
	<script type="text/javascript" src="/static/fsLayui/plugins/layui/layui.js"></script>
	<script type="text/javascript" src="/static/fsLayui/plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="/static/fsLayui/plugins/frame/js/fsDict.js?v=1.5.0"></script>
	<script type="text/javascript" src="/static/fsLayui/plugins/frame/js/fs.js?v=1.5.0"></script>
	<script type="text/javascript" src="/static/fsLayui/plugins/frame/js/frame.js?v=1.5.0"></script>
</head>
<body>
<div class="layui-fluid">
	<div class="layui-row layui-col-space1">
		<div class="layui-col-md12">
			<div class="layui-row grid-demo">
				<div class="layui-col-md3">
					<button class="layui-btn layui-btn-danger" function="submit" url="/admin/comment/delete" isMutiDml="1" isConfirm="1" confirmMsg="是否确定删除选中的数据？" inputs="commentId:">
						<i class="layui-icon">&#xe640;</i>批量删除
					</button>
					<button class="layui-btn" function="refresh">
						<i class="layui-icon">&#x1002;</i>刷新
					</button>
				</div>
				<div class="layui-col-md12">
					<table id="fsDatagrid" lay-filter="fsDatagrid" class="fsDatagrid" isLoad="1" url="/admin/comment/list" isPage="1" defaultForm="query_form" height="full-135"></table>

					<div class="fsDatagridCols">
						<p type="numbers" title="#"/>
						<p checkbox="true"/>
						<p field="content" title="评论内容" />
						<p field="article" align="center" title="评论帖子" templet="#articleTpl" />
						<p field="commentDate" align="center" title="评论日期" sort="true"/>
						<p field="user" align="center" title="评论用户" sort="true" templet="#userTpl" />
						<p field="state" align="center" title="审核状态" sort="true" templet="#stateTpl" />
						<p field="isPass" align="center" title="审核通过?" sort="true" templet="#isPassTpl" />
						<p fixed="right" align="center" toolbar="#barDemo" title="操作"/>
					</div>

					<script type="text/html" id="articleTpl">
						<a target="_blank" href="/foreground/detail/{{ d.article.articleId }}.html" >{{d.article.name}}</a>
					</script>

					<script type="text/html" id="userTpl">
						<img src="/static/img/{{d.user.headPortrait}}" class="layui-nav-img" /> {{d.user.nickname}}({{d.user.userName}})
					</script>

					<script type="text/html" id="stateTpl">
						{{#  if(d.state == 0){ }}
							<font color="green">待审核</font>
						{{# } else if(d.state == 1){ }}
							<font color="blue">审核通过</font>
						{{# } else if(d.state == 2){ }}
							<font color="red">审核未通过</font>
						{{#  } }}
					</script>

					<script type="text/html" id="isPassTpl">
						<input type="checkbox" name="isPass" value="{{d.commentId}}" lay-skin="switch" lay-text="是|否" lay-filter="isPass"  {{ d.state == 1 ? 'checked' : '' }}>
					</script>

					<script type="text/html" id="barDemo">
						<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="submit" url="/admin/comment/delete" isConfirm="1" confirmMsg="是否确定删除当前记录？" inputs="commentId:"><i class="layui-icon">&#xe640;</i>删除</a>
					</script>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;

        //监听审核操作
        form.on('switch(isPass)', function(obj){
            $.post("/admin/comment/updateState",{commentId:this.value,state:obj.elem.checked},function(res){
				if(res.success == true){
                    table.reload('fsDatagrid', {
                        url: '/admin/comment/list'
                        ,where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                    layer.msg('操作成功');
				}else{
                    layer.msg('操作失败');
				}
			});
        });
    });
</script>

</body>
</html>
